/**
 * 系统相关类型定义
 */

/**
 * 系统信息
 */
export interface SystemInfo {
  platform: NodeJS.Platform
  arch: string
  version: string
  release: string
  hostname: string
  uptime: number
  loadavg: number[]
  totalmem: number
  freemem: number
  cpus: CpuInfo[]
  networkInterfaces: Record<string, NetworkInterface[]>
  userInfo: UserInfo
  osType: string
  osRelease: string
  osVersion: string
  endianness: 'BE' | 'LE'
  homedir: string
  tmpdir: string
}

/**
 * CPU信息
 */
export interface CpuInfo {
  model: string
  speed: number
  times: {
    user: number
    nice: number
    sys: number
    idle: number
    irq: number
  }
}

/**
 * 网络接口信息
 */
export interface NetworkInterface {
  address: string
  netmask: string
  family: 'IPv4' | 'IPv6'
  mac: string
  internal: boolean
  cidr: string | null
  scopeid?: number
}

/**
 * 用户信息
 */
export interface UserInfo {
  uid: number
  gid: number
  username: string
  homedir: string
  shell: string | null
}

/**
 * 内存使用情况
 */
export interface MemoryUsage {
  total: number
  free: number
  used: number
  available: number
  usagePercent: number
  swapTotal?: number
  swapFree?: number
  swapUsed?: number
  swapPercent?: number
}

/**
 * CPU使用情况
 */
export interface CpuUsage {
  model: string
  cores: number
  usage: number
  loadAverage: number[]
  temperature?: number
  frequency?: number
}

/**
 * 磁盘信息
 */
export interface DiskInfo {
  filesystem: string
  type: string
  size: number
  used: number
  available: number
  usagePercent: number
  mountpoint: string
}

/**
 * 网络统计
 */
export interface NetworkStats {
  interface: string
  bytesReceived: number
  bytesSent: number
  packetsReceived: number
  packetsSent: number
  errorsReceived: number
  errorsSent: number
  droppedReceived: number
  droppedSent: number
}

/**
 * 进程信息
 */
export interface ProcessInfo {
  pid: number
  ppid: number
  name: string
  cmd: string
  cpu: number
  memory: number
  state: string
  startTime: string
  user: string
}

/**
 * 系统性能指标
 */
export interface SystemPerformance {
  timestamp: string
  cpu: CpuUsage
  memory: MemoryUsage
  disk: DiskInfo[]
  network: NetworkStats[]
  processes: ProcessInfo[]
  uptime: number
  loadAverage: number[]
}

/**
 * 系统监控配置
 */
export interface SystemMonitorConfig {
  enabled: boolean
  interval: number
  metrics: {
    cpu: boolean
    memory: boolean
    disk: boolean
    network: boolean
    processes: boolean
  }
  thresholds: {
    cpuWarning: number
    cpuCritical: number
    memoryWarning: number
    memoryCritical: number
    diskWarning: number
    diskCritical: number
  }
  alerts: {
    enabled: boolean
    email?: string
    webhook?: string
  }
}

/**
 * 系统路径信息
 */
export interface SystemPaths {
  home: string
  appData: string
  userData: string
  temp: string
  desktop: string
  documents: string
  downloads: string
  music: string
  pictures: string
  videos: string
  logs: string
  crashDumps: string
}

/**
 * 环境变量
 */
export interface EnvironmentVariables {
  [key: string]: string | undefined
}

/**
 * 系统服务状态
 */
export interface SystemService {
  name: string
  displayName: string
  status: 'running' | 'stopped' | 'paused' | 'unknown'
  startType: 'auto' | 'manual' | 'disabled'
  pid?: number
  description?: string
}

/**
 * 系统事件
 */
export interface SystemEvent {
  id: string
  type: 'startup' | 'shutdown' | 'suspend' | 'resume' | 'lock' | 'unlock'
  timestamp: string
  source: string
  description?: string
  metadata?: any
}

/**
 * 电源状态
 */
export interface PowerStatus {
  isOnBattery: boolean
  batteryLevel?: number
  isCharging?: boolean
  timeRemaining?: number
  powerSource: 'ac' | 'battery' | 'ups' | 'unknown'
}

/**
 * 显示器信息
 */
export interface DisplayInfo {
  id: number
  bounds: {
    x: number
    y: number
    width: number
    height: number
  }
  workArea: {
    x: number
    y: number
    width: number
    height: number
  }
  scaleFactor: number
  rotation: number
  touchSupport: 'available' | 'unavailable' | 'unknown'
  monochrome: boolean
  accelerometerSupport: 'available' | 'unavailable' | 'unknown'
  colorSpace: string
  colorDepth: number
  depthPerComponent: number
  displayFrequency: number
  isPrimary: boolean
  isInternal: boolean
}

/**
 * 音频设备信息
 */
export interface AudioDevice {
  id: string
  name: string
  type: 'input' | 'output'
  isDefault: boolean
  isActive: boolean
  channels: number
  sampleRate: number
  bitDepth: number
}

/**
 * 系统权限
 */
export interface SystemPermission {
  type: 'microphone' | 'camera' | 'location' | 'notifications' | 'accessibility' | 'fullDiskAccess'
  status: 'granted' | 'denied' | 'restricted' | 'unknown'
  canRequest: boolean
}

/**
 * 系统安全信息
 */
export interface SystemSecurity {
  isSecureBootEnabled?: boolean
  isTpmEnabled?: boolean
  isFirewallEnabled?: boolean
  isAntivirusEnabled?: boolean
  lastSecurityUpdate?: string
  securityLevel: 'low' | 'medium' | 'high'
  vulnerabilities: Array<{
    id: string
    severity: 'low' | 'medium' | 'high' | 'critical'
    description: string
    recommendation: string
  }>
}

/**
 * 系统备份信息
 */
export interface SystemBackup {
  id: string
  name: string
  type: 'full' | 'incremental' | 'differential'
  size: number
  location: string
  createdAt: string
  status: 'completed' | 'failed' | 'in-progress'
  error?: string
}

/**
 * 系统更新信息
 */
export interface SystemUpdate {
  id: string
  title: string
  description: string
  version: string
  size: number
  type: 'security' | 'feature' | 'bugfix' | 'driver'
  priority: 'low' | 'medium' | 'high' | 'critical'
  releaseDate: string
  installDate?: string
  status: 'available' | 'downloading' | 'downloaded' | 'installing' | 'installed' | 'failed'
  requiresRestart: boolean
}

/**
 * 系统诊断信息
 */
export interface SystemDiagnostics {
  timestamp: string
  overallHealth: 'good' | 'warning' | 'critical'
  issues: Array<{
    category: 'performance' | 'security' | 'storage' | 'network' | 'hardware'
    severity: 'low' | 'medium' | 'high'
    title: string
    description: string
    recommendation: string
    autoFixAvailable: boolean
  }>
  recommendations: Array<{
    title: string
    description: string
    impact: 'low' | 'medium' | 'high'
    effort: 'easy' | 'moderate' | 'difficult'
  }>
}

/**
 * 系统配置
 */
export interface SystemConfig {
  monitoring: SystemMonitorConfig
  security: {
    enableFirewall: boolean
    enableAutoUpdates: boolean
    enableTelemetry: boolean
    allowRemoteAccess: boolean
  }
  performance: {
    enableHardwareAcceleration: boolean
    maxCpuUsage: number
    maxMemoryUsage: number
    enablePowerSaving: boolean
  }
  privacy: {
    enableAnalytics: boolean
    enableCrashReporting: boolean
    enableUsageStatistics: boolean
    shareSystemInfo: boolean
  }
}
